/*
 * Package il.ac.biu.cs.grossmm.api.data
 * File Notifier.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 */



package il.ac.biu.cs.grossmm.api.flow;

import il.ac.biu.cs.grossmm.api.data.Root;
import il.ac.biu.cs.grossmm.api.keys.Key;

public interface Notifier<N> {
    
    /**
     * Attempts to subscribe to notifications about changes in data 
     * associated with the given key.
     * 
     * This method should determine whether the key matches any
     * data that can be provided by this notifier. The method should
     * return fast (e.g. it should not perform any I/O operations
     * if possible).
     * 
     * <p>
     * There are four possible scenarios:
     * <ul>
     * <li> This method calls <tt>NotificationPoint.activated</tt>
     * and returns <tt>true</tt>. In this case a subscription is created
     * in an activated state.
     * <li> This method calls <tt>NotificationPoint.deactivated</tt>
     * and returns <tt>true</tt>. In this case a subscription is created
     * in an deactivated state with status set by 
     * <tt>NotificationPoint.deactivated</tt> method invokation.
     * <li> This method does not call <tt>NotificationPoint.activated</tt> or
     * <tt>NotificationPoint.deactivated</tt>
     * and returns <tt>true</tt>. In this case a subscription is created
     * in an deactivated state and its subscription status is set to "INIT".
     * <li> This method does not call <tt>NotificationPoint.activated</tt> or
     * <tt>NotificationPoint.deactivated</tt>
     * and returns <tt>false</tt>. In this case subscription is not created 
     * since the key does not match the notifier's criteria. 
     * </ul>
     * 
     * 
     * @param key the key associated with data to subscribe to
     * @param track subscription tracker
     *  
     * @return true if subscription key matched the notifier
     * @throws Exception 
     */
	boolean subscribe(Key key, Track track) throws Exception;
    
    /**
     * Unsubscribes from notifications about changes in data 
     * associated with the given key
     * @param key the key associated with data to unsubscribe from 
     */
	void unsubscribe(Key key);
    
    /**
     * Fetch data associated with the given key
     * 
     * @param key the key associated with data to fetch
     * @param node fetched data node, or null if no data is currently associated
     *  with the key
     */
    void fetch(Key key, Track track, Root<N> node, NodeManipulator manipulator);
    
}
